package com.example.demo.service;

import com.example.demo.entity.Member;
import com.example.demo.mapper.MemberMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

/**
 * 会员MyBatis服务层
 */
@Service
public class MemberMyBatisService {
    
    @Autowired
    private MemberMapper memberMapper;
    
    /**
     * 根据会员等级查询会员
     */
    public List<Member> findByMemberLevel(String memberLevel) {
        return memberMapper.findByMemberLevel(memberLevel);
    }
    
    /**
     * 查询即将过生日的会员
     */
    public List<Member> findBirthdayMembers(Integer days) {
        return memberMapper.findBirthdayMembers(days);
    }
    
    /**
     * 查询长期未消费的会员
     */
    public List<Member> findInactiveMembers(Integer days) {
        return memberMapper.findInactiveMembers(days);
    }
    
    /**
     * 查询高价值会员
     */
    public List<Member> findHighValueMembers(Double minConsumption) {
        return memberMapper.findHighValueMembers(minConsumption);
    }
    
    /**
     * 统计会员总数
     */
    public Long countMembers() {
        return memberMapper.countMembers();
    }
    
    /**
     * 统计各等级会员数量
     */
    public List<Map<String, Object>> countMembersByLevel() {
        return memberMapper.countMembersByLevel();
    }
    
    /**
     * 查询会员消费排行
     */
    public List<Map<String, Object>> getTopConsumingMembers(Integer limit) {
        return memberMapper.getTopConsumingMembers(limit);
    }
    
    /**
     * 查询新注册会员统计
     */
    public List<Map<String, Object>> getNewMembersByMonth(Integer year) {
        return memberMapper.getNewMembersByMonth(year);
    }
    
    /**
     * 查询会员积分统计
     */
    public Map<String, Object> getPointsStatistics() {
        return memberMapper.getPointsStatistics();
    }
    
    /**
     * 根据消费金额范围查询会员
     */
    public List<Member> findByConsumptionRange(Double minAmount, Double maxAmount) {
        return memberMapper.findByConsumptionRange(minAmount, maxAmount);
    }
    
    /**
     * 查询会员活跃度统计
     */
    public List<Map<String, Object>> getMemberActivityStats() {
        return memberMapper.getMemberActivityStats();
    }
    
    /**
     * 根据注册时间查询会员
     */
    public List<Member> findByRegisterDateRange(LocalDate startDate, LocalDate endDate) {
        return memberMapper.findByRegisterDateRange(startDate, endDate);
    }
}
